import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        Solution solution = new Solution();
        String s = "cbaebabacd";
        String p = "abc";
        System.out.println(solution.findAnagrams(s, p));
    }
}
class Solution {
    public List<Integer> findAnagrams(String s, String p) {
        int[] hash1 = new int[26];
        int[] hash2 = new int[26];
        List<Integer> list = new ArrayList<>();
        int ret = 0;
        int n = p.length();
        for (int i = 0;i < p.length();i++) {
            hash2[p.charAt(i)-97]++;
        }
        for (int right = 0,left = 0;right < s.length();right++) {
            //进窗口
            hash1[s.charAt(right)-97]++;
            //出窗口
            if (right-left+1>n) {
                hash1[s.charAt(left)-97]--;
                left++;
            }
            //更新结果
            if (check(hash1,hash2)) {
                list.add(left);
            }
        }
        return list;
    }
    private boolean check (int[] hash1,int[] hash2) {
        for (int i = 0;i < hash1.length;i++) {
            if (hash1[i]!=hash2[i]) return false;
        }
        return true;
    }
}